package rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.servlet;

import java.io.IOException;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.dao.PutnikDao;
import rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.entitet.Putnik;

@SuppressWarnings("serial")
public class PromenaPutnikaKontroler extends HttpServlet {

	@EJB
	private PutnikDao cPutnikDao;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		int id = Integer.parseInt(req.getParameter("id"));
		Putnik putnik = cPutnikDao.pronadjiPoId(id);
		req.setAttribute("putnik", putnik);

		getServletContext().getRequestDispatcher("/PrikazPutnikaKontroler")
				.forward(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		long jmbg = Long.parseLong(req.getParameter("jmbg"));
		String ime = req.getParameter("ime");
		String prezime = req.getParameter("prezime");

		Putnik putnik = (Putnik) req.getAttribute("putnik");
		putnik.setJmbg(jmbg);
		putnik.setIme(ime);
		putnik.setPrezime(prezime);
		cPutnikDao.stopi(putnik);

		getServletContext().getRequestDispatcher("/PrikazPutnikaKontroler")
				.forward(req, resp);
	}
}
